/**
 *@program: getx_simple_code
 *@description:
 *@author: Ming
 *@create: 2023-12-27 14:49
 *@version v1.0
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_simple_code/common/routes/app_routes.dart';
import 'package:getx_simple_code/pages/list_detail/index.dart';

class RouterView extends StatelessWidget {
  const RouterView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("路由展示"),
      ),
      body: ListView(
        children: [
// 路由&导航
          ListTile(
            title: Text("导航-命名路由list"),
            subtitle: Text('Get.toNamed("/list")'),
            onTap: () => Get.toNamed("/list"),
          ),
          ListTile(
            title: Text("导航-命名路由list > detail"),
            subtitle: Text('Get.toNamed("/list/detail")'),
            onTap: () => Get.toNamed("/list/detail"),
          ),
          ListTile(
            title: Text("导航-类对象"),
            subtitle: Text("Get.to(DetailView())"),
            onTap: () => Get.to(DetailView()),
          ),
          ListTile(
            title: Text("导航-清除上一个"),
            subtitle: Text("Get.offNamed(AppRoutes.Login)"),
            onTap: () => Get.offNamed(AppRoutes.Login),
          ),
          ListTile(
            title: Text("导航-清除所有"),
            subtitle: Text("Get.offAllNamed(AppRoutes.Login)"),
            onTap: () => Get.offAllNamed(AppRoutes.Login),
          ),
          Divider(),
          ListTile(
            title: Text("导航-arguments传值+返回值"),
            subtitle: Text(
                'Get.toNamed("/list/detail", arguments: {"id": 111})'),
            onTap: () async {
              var result = await Get.toNamed("/list/detail",
                  arguments: {"id": 111});
              Get.snackbar("返回值", "success -> " + result["success"].toString());
            },
          ),
          ListTile(
            title: Text("导航-parameters传值+返回值"),
            subtitle: Text('Get.toNamed("/list/detail?id=222")'),
            onTap: () async {
              var result = await Get.toNamed("/list/detail?id=222");
              Get.snackbar("返回值", "success -> " + result["success"].toString());
            },
          ),
          ListTile(
            title: Text("导航-参数传值+返回值"),
            subtitle: Text('Get.toNamed("/list/detail/333")'),
            onTap: () async {
              var result = await Get.toNamed("/list/detail/333");
              Get.snackbar("返回值", "success -> " + result["success"].toString());
            },
          ),
          Divider(),
          ListTile(
            title: Text("导航-not found"),
            subtitle: Text('Get.toNamed("/aaa")'),
            onTap: ()  =>Get.toNamed("/aaa"),
          ),
          Divider(),
          ListTile(
            title: Text("导航-中间件-认证Auth"),
            subtitle: Text('Get.toNamed(AppRoutes.My)'),
            onTap: () => Get.toNamed(AppRoutes.My),
          ),
        ],
      ),
    );
  }
}